package com.aivin.mobileApi;

import com.aivin.entity.*;
import com.aivin.service.FileDetailService;
import com.aivin.service.HotestStarService;
import com.aivin.utils.MyStringUtils;
import com.aivin.utils.MyValidateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONAware;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 获取 推荐的明星 。
 */
@Controller
@RequestMapping("/hotestStarApi")
public class HotestStarController {
    @Autowired
    public HotestStarService hotestStarService;

    /***
     * http://192.168.0.119:8081/findYou/hotestStarApi/getStarBySex/android/boy/time/0/5
     * 获取指定条数的数据 。  分页
     * 仅支持Get
     *  @param whichSys ios 、android
     * @param pSex     boy 、girl
     * @param sortType time、heat
     * @param offset   起始点
     * @param limit    条数
     * @return json array  string
     */
    @RequestMapping(value = "/getStarBySex/{whichSys}/{pSex}/{sortType}/{offset}/{limit}", method = {RequestMethod.GET},
            produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String getStarBySex(@PathVariable String whichSys, @PathVariable String pSex, @PathVariable String sortType, @PathVariable int offset, @PathVariable int limit) {
        List<HotestStar> resultList = hotestStarService.getStarBySex(pSex, sortType, offset, limit);

        //过滤掉不需要显示的属性
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
        filter.getExcludes().add("mId");

        filter.getExcludes().add("pId");
        filter.getExcludes().add("pShow");
        filter.getExcludes().add("pPy");
        String jsonStr = JSONObject.toJSONString(resultList ,filter);
//        String jsonStr = JSONObject.toJSONString(resultList);
        return jsonStr;

    }


    /**
     * http://192.168.0.119:8081/findYou/hotestStarApi/queryStarByKey
     * 仅支持  Post
     * 根据关键字进行模糊搜索
     * @param whichSys ios /android
     * @param keyWord   支持中文、全拼 、首字母 例如  ： 黄晓明 / huangxiaoming / hxm /
     * @return json array  String
     */
    @RequestMapping(value = "/queryStarByKey", method = {RequestMethod.POST}, produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String queryStarByKey(@RequestParam("whichSys") String whichSys, @RequestParam("keyWord") String keyWord) {
        List<HotestStar> resultList = hotestStarService.queryStarByKey(keyWord);

        //过滤掉不需要显示的属性
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
        filter.getExcludes().add("pId");
        filter.getExcludes().add("pShow");
        filter.getExcludes().add("pPy");
        String jsonStr = JSONObject.toJSONString(resultList ,filter);

       // String jsonStr = JSONObject.toJSONString(resultList);
        return jsonStr;
    }


}
